﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Collections.Generic;

namespace Jy123.Web.Guess
{
    public partial class Index : System.Web.UI.Page
    {
        protected int userID = 28;//暂时测试用户28
        protected void Page_Load(object sender, EventArgs e)
        {
            string struserIDFromCookie = Common.Cookie.getCookie("userID");
            if (string.IsNullOrEmpty(struserIDFromCookie))
            {
                Response.Redirect("/");
            }
            else
            {
                userID = int.Parse(struserIDFromCookie);
            }

            PageLoad();      //加载页面
        }
        protected void PageLoad()
        {
            Model.User_Main userModel = new BLL.User_Main().GetModel(userID);

            StringBuilder sbHtml = new StringBuilder(Cache["guess_index"].ToString());//主sb

            //公共部分
            sbHtml = sbHtml.Replace("$Javascript$", Cache["guess_js"].ToString());//JS
            sbHtml = sbHtml.Replace("$Header$", Cache["user_header"].ToString());//头部
            sbHtml = sbHtml.Replace("$Footer$", Cache["user_footer"].ToString());//底部
            sbHtml = sbHtml.Replace("$Navigation$", Cache["user_navigation_down"].ToString());//左侧导航
            sbHtml = sbHtml.Replace("$LeftUserFriendAdd$", Cache["user_friendadd"].ToString());//左侧快速添加好友
            sbHtml = sbHtml.Replace("$GuessLogo$", Cache["guess_logo"].ToString());//竞猜LOGO
            sbHtml = sbHtml.Replace("$GuessMenu$", Cache["guess_menu"].ToString());//竞猜菜单
            sbHtml = sbHtml.Replace("$IndexClass$", "class=\"sel\"")//菜单按钮样式
                .Replace("$AddClass$", "")
                .Replace("$MyFriendClass$", "")
                .Replace("$MyCreateClass$", "")
                .Replace("$MyJoinClass$", "")
                .Replace("$TopClass$", "class=\"last\"")
                .Replace("$Cash$", Convert.ToInt32(userModel.Cash).ToString("n0"));

            sbHtml = sbHtml.Replace("$Content$", Cache["guess_indexmain"].ToString());//竞猜主页面

            sbHtml = sbHtml.Replace("$GuessIndexButton$", Cache["guess_indexbutton"].ToString());//竞猜按钮

            sbHtml = sbHtml.Replace("$GuessDynamicLi$", getGuessDynamic());//竞猜动态

            Response.Write(sbHtml.ToString()); 
        }
        
        /// <summary>
        /// 获取竞猜动态
        /// </summary>
        /// <returns>动态HTML</returns>
        protected string getGuessDynamic()
        {
            StringBuilder sbHtml = new StringBuilder();

            List<BLL.Public.State.StateClass> stateList =  new BLL.Public.State().GetState(1,10,userID,false,false,0,0);

            foreach (BLL.Public.State.StateClass state in stateList)
            {
                string str = "<li><span>{0}</span> {1}</li>";

                sbHtml.AppendFormat(str, state.STRTIME, state.HTML);
            }

            return sbHtml.ToString();
        }
    }
}
